package com.scoresystem.web.controller.dispatcher;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.scoresystem.common.CommonValue;
import com.scoresystem.web.service.TeacherService;
import com.scoresystem.web.ui.bridge.ViewBridgeImpl;
import com.scoresystem.web.ui.view.ViewFactory;

import net.sf.json.JSONObject;

public class TeacherDispatcher extends BaseDispatcher implements IDispatcher {

	private TeacherService service;
	public TeacherDispatcher(){
		showable=null;
		viewbridge=new ViewBridgeImpl();
		service=new TeacherService();
	}
	@Override
	public void dispatch(String option, HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		//查看成绩录入情况
		if(option.equals(CommonValue.REQUEST_OP_LOOKOUTSCORE)){
			showable=ViewFactory.createShowTeaLookOutView();
			JSONObject json=service.checkoutStuScores(request.getParameter("stuclass"),
					request.getParameter("coursename"));
			viewbridge.setShowable(showable).showView(json, request, response);
		}
		//录入成绩
		if(option.equals(CommonValue.REQUEST_OP_INSERTSCORE)){
			showable=ViewFactory.createShowInsertScoreView();
			JSONObject json=service.checkoutInsertScore
					(request.getParameter("stuclass"), request.getParameter("coursename"),
							request.getParameter("worknum"),
							request.getParameter("stunums"), request.getParameter("scores"),
							request.getParameter("stunames"));
			viewbridge.setShowable(showable).showView(json, request, response);
		}
		//教师查看学生反馈
		if(option.equals(CommonValue.REQEUST_OP_LOOKOUTREMARK)){
			showable=ViewFactory.createShowLookOutRemarkView();
			JSONObject json=service.checkoutLookOutRemark(request.getParameter("worknum"));
			viewbridge.setShowable(showable).showView(json, request, response);
		}
		//教师修改学生成绩
		if(option.equals(CommonValue.REQUEST_OP_UPDATESCORE)){
			showable=ViewFactory.createShowTeaUpdateScoreView();
			JSONObject json=service.checkoutUpdate
					(request.getParameter("stuclass"), request.getParameter("coursename"),
							request.getParameter("worknum"),
							request.getParameter("stunum"),
							request.getParameter("score"));
			viewbridge.setShowable(showable).showView(json, request, response);
		}

	}

}
